package com.uzhie.media;

import com.alibaba.fastjson.JSONObject;
import com.uzhie.media.bean.MediaMsgBean;
import com.uzhie.media.spring.MethodInvoke;
import org.apache.log4j.Logger;

import java.lang.reflect.InvocationTargetException;

/**
 * Created by TangFei on 2018/7/26.
 */
public class MediaDispatcher {

    private Logger logger = Logger.getLogger(this.getClass());

    private MethodInvoke methodInvoke;

    public void setMethodInvoke(MethodInvoke methodInvoke) {
        this.methodInvoke = methodInvoke;
    }

    public MediaMsgBean dispatch(MediaMsgBean msgBean) throws InterruptedException, InvocationTargetException, IllegalAccessException {
        Object invoke = methodInvoke.invoke(msgBean.getMsgID(), msgBean.getMsgID(), msgBean.getMsgBody());
        switch (msgBean.getMsgID()) {
            case MediaConstant.MSG_ID.PLA_REQ_ONLINE_CHANNEL:
                logger.debug("消息ID " + msgBean.getHexMsgID() + " 这是流媒体响应给服务平台的消息 无需应答！");
                msgBean.setMsgBody(null);
                break;
            case MediaConstant.MSG_ID.PLA_REQ_CHANNEL_TYPE_NUMBER:
                logger.debug("消息ID " + msgBean.getHexMsgID() + " 这是流媒体响应给服务平台的消息 无需应答！");
                msgBean.setMsgBody(null);
                break;
            case MediaConstant.MSG_ID.PLA_REQ_PLAY_STATUS_KEEP:
                logger.debug("消息ID " + msgBean.getHexMsgID() + " 这是流媒体响应给服务平台的消息 无需应答！");
                msgBean.setMsgBody(null);
                break;
            default:
                msgBean.setMsgBody((JSONObject) invoke);
        }
        return msgBean;
    }

}
